import React from 'react';
import InfoModal from '@/pages/Task/components/InfoModal';
import { history } from 'umi'
import { TaskAuditType, PageFromType } from '@/pages/Task/utils';

// 不可操作审核（通过、不通过）时的提示框
export const showCantCheckInfoModal = data => {
    const key = '_temp';
    const { taskId: id, taskAuditStatus } = data;
    let title;
    const query = { id };
    if (TaskAuditType.INIT === taskAuditStatus) {
        title = '当前任务的上一级任务未审核，请先审核上一级任务';
        query.type = PageFromType.AUDIT;
    } else if (TaskAuditType.REFUSE === taskAuditStatus) {
        title = '上一级任务审核不通过，当前任务不允许审核通过';
    }
    const dataSource = { [key]: title, ...data };
    let model = { destroy: () => {} };
    const renderTaskName = value => {
        const handleClick = () => {
            setImmediate(() => {
                history.push({
                    pathname: '/work/task/taskdetail',
                    query,
                    state: { tabRoute: true, tabRefresh: true }
                });
            });
            model.destroy();
        };
        return <a onClick={handleClick}>{value}</a>;
    };
    const columns = [
        {
            single: true,
            dataIndex: key
        },
        {
            title: '上一级任务名称',
            dataIndex: 'taskName',
            render: renderTaskName
        },
        {
            title: '上一级任务编号',
            dataIndex: 'taskNo'
        }
    ];
    model = InfoModal.showCommonModal({ columns, dataSource, title: '提示' });
    return model;
};
